package com.tl.commonlibrary.tool;

import android.content.Context;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;

/**
 * Created by a on 2015/7/20.
 */
public class AnimUtil {
    /**
     * 按钮点击效果
     *
     * @param context
     * @param view
     * @param animId
     * @param interpolator
     * @param listener
     */
    public static void setAnimation(Context context, View view, int animId, Interpolator interpolator, Animation.AnimationListener listener) {
        Animation animation = AnimationUtils.loadAnimation(context, animId);
        if (listener != null) {
            animation.setAnimationListener(listener);
        }
        if (interpolator != null) {
            animation.setInterpolator(interpolator);
        }
        view.startAnimation(animation);
    }
    public static AlphaAnimation startAlphaAnimation(View view,float from,float to,int duration){
       return startAlphaAnimation(view,from,to,duration,null);
    }
    public static AlphaAnimation startAlphaAnimation(View view, float from, float to, int duration, Animation.AnimationListener animationListener){
        AlphaAnimation alphaAnimation = new AlphaAnimation(from,to);
        alphaAnimation.setDuration(duration);
        alphaAnimation.setInterpolator(new LinearInterpolator());
        view.startAnimation(alphaAnimation);
        alphaAnimation.setAnimationListener(animationListener);
        return alphaAnimation;
    }
//    public static TranslateAnimation moveInFromRight(){
//        TranslateAnimation animation = new TranslateAnimation(0,100%,0,0);
//    }
}
